package cn.com.yang.litecode;

/**
 * 
 * licode测试题，两数相加
 * @author yangyijin
 * @date 2022年11月6日-下午12:40:04
 */
public class ListNode {
	int val;
	ListNode next;
	public ListNode() {}
	public ListNode(int val, ListNode next) {
		this.val = val;
		this.next = next;
	}
	public ListNode(int val) {
		this.val = val;
	}
	
	
	public ListNode addTwoNumers(ListNode l1,ListNode l2) {
		ListNode sumNode = new ListNode(0);
		int sum =0;
		int carry=0;
		ListNode pp = sumNode;
		while(l1!=null && l2 !=null || carry !=0) {
			int l1_val = l1 !=null?l1.val:0;
			int l2_val = l2 !=null?l2.val:0;
			sum = l1_val + l2_val+sum;
			carry = sum/10;
			// 这一步干嘛？
			ListNode node = new ListNode(sum%10);
			pp.next =node;
			pp = node;
			
		}
		return sumNode;
	}
}
